package fr.emse.tatiana.filter;

import java.io.*;
import java.util.*;

public class RemoveLines {
	
	private BufferedReader reader;
	private BufferedWriter writer;
	private List<String> buffer;

	/**
	 * Open inname, remove specified number of lines at beginning and end, save to outname
	 * 
	 * @param inname open this filename
	 * @param outname save to this filename
	 * @param beginlines number of lines to remove at beginning
	 * @param endlines number of lines to remove at end
	 * @throws IOException 
	 */
	public RemoveLines(String inname, String outname, int beginlines, int endlines) throws IOException {
		reader = new BufferedReader(new FileReader(inname));
		writer = new BufferedWriter(new FileWriter(outname));
		buffer = new Vector<String>();
		for (String s = reader.readLine(); s!=null; s=reader.readLine()) {
			buffer.add(s);
		}
		
		boolean firstline=true;
		for (int i=beginlines; i<buffer.size()-endlines;i++) {
			if (firstline) {
				firstline=false;
			} else {
				writer.write("\n");
			}
			writer.write(buffer.get(i));
		}
		writer.flush();
		writer.close();
	}
	
}
